<template>
	<view class="content"> 
		<view class="title">
			<view class="register">
				<image src="../../../static/logo@2x.png" mode=""></image>
				<input class="phone" maxlength="11" placeholder="手机号码" v-model="mobile" />
				<u-form-item :label-position="labelPosition" label="验证码" prop="code" label-width="100" class="froms">
					<u-input :border="border" placeholder="请输入验证码" v-model="model.code" type="text"></u-input>
					<u-button slot="right" type="success" size="mini" @click="getCode">{{codeTips}}</u-button>
				</u-form-item>
				<input class="phone" maxlength="15" type="password" placeholder="请设置新密码，6-15位" v-model="passwork" />
				<button class="bt1" type="default">确定</button>
				<!-- <view class="option">
					<p class="option_tetx1">账号密码登录</p>
				</view> -->
				<u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				title: '注册',
				labelPosition: 'left',
				model: {
					code: '',
					region: '',
				},
				codeTips:'',
				border: false,
				pickerShow: false,
				passwork:'',
				mobile:''
			}
		},
		components:{
			
		},
		onLoad() {
	
		},
		methods: {
			// 选择地区回调
			regionConfirm(e) {
				this.model.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
			},
			labelPositionChange(index) {
				this.labelPosition = index == 0 ? 'left' : 'top';
			},
			codeChange(text) {
				this.codeTips = text;
			},
			getCode() {
				let data={
					mobile:this.mobile
				}
				this.$api.code(data).then(res => {
					console.log(res)
				}, err => {
					
				})
				if(this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码',
						mask: true
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						this.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					this.$u.toast('倒计时结束后再发送');
				}
			},
			login() {
				let data = {
					mobile: this.mobile,
					verify_code:this.model.code,
					new_passwork:this.passwork
				}
				this.$api.forgetPwd(data).then(res => {
					this.$common.successToShow(res.data.msg,()=>{})
					if (res.data.msg==="修改成功") {
						console.log(res)
						this.$db.set('userToken', res.data.data.token)
						this.$common.successToShow(res.data.msg,()=>{
							uni.redirectTo({
							    url: '../login/index'
							});
						})
					}
				}, err => {})
			}
		}
	}
</script>
<style lang="less">
	.content{
		background-image: url(../../../static/img-d.png);
		width: 750rpx;
		height: 1334rpx;
		background-size:cover;
		background-repeat:no-repeat;
		
		.title{
			background-image: url(../../../static/img_t.png);
			background-size:cover;
			background-repeat:no-repeat;
			width: 750rpx;
			height: 478rpx;
			position: relative;
			.register{
				width: 560rpx;
				height: 916rpx;
				background: #FFFFFF;
				border-radius: 16rpx;
				position: absolute;
				left:50%;
				transform: translate(-50%,20%);
				text-align: center;
				padding: 66rpx 40rpx 0 40rpx;
				
				image{
					width: 156rpx;
					height: 184rpx;
				}
				.phone{
					text-align: left;
					width: 100%;
					border-bottom: 1px solid #D2D2D2;
					margin-top:40rpx;
					font-size: 24rpx;
					color: #C1C1C1;
					height: 80rpx;
				}
				.bt1{
					margin-top: 40rpx;
					height: 78rpx;
					background: linear-gradient(77deg, #4E7BFA 0%, #764CFA 100%);
					font-size: 28rpx;
					color: #FFFFFF;
					line-height: 78rpx;
				}
				.bt2{
					margin-top: 40rpx;
					height: 78rpx;
					border: 1px solid #764CFA;
					opacity: 1;
					border-radius: 4px;
					color: #764CFA;
					font-size: 28rpx;
				}
				.option{
					margin-top: 20rpx;
					display: flex;
					justify-content: space-between;
					height: 30rpx;
					.option_tetx1{
						color: #764CFA;
						font-size: 20rpx;
					}
				}
				.froms{
					color: #c1c1c1;
				}
			}
		}
	}
</style>